home *** CD-ROM | disk | FTP | other *** search
- source mclistbox.tcl
- source getenv.tcl
- source filesel.tcl
- source about.tcl
- source prefs.tcl
-
- set appdir [pwd]
- cd ../Resources
- set messdir [pwd]
- set MESSHOME [getenv MESSHOME [pwd]]
- cd "$messdir/../../.."
- set approot [pwd]
- set EDITOR [getenv EDITOR "open -t"]
- cd "$appdir"
-
- wm title . "MessMenu"
-
- #Declare that there is a menu
- menu .mbar
- . config -menu .mbar
- .mbar add cascade -label "Help" -underline 0 -menu [menu .mbar.help -tearoff 0]
- .mbar.help add command -label "About" -command { about }
- .mbar add cascade -label "MessMenu" -underline 0 -menu [menu .mbar.messmenu -tearoff 0]
- .mbar.messmenu add command -label "Preferences" -command { prefs }
- .mbar.messmenu add command -label "Edit mess.ini" -command { exec /bin/sh -c "$EDITOR '$MESSHOME/mess.ini'" }
- .mbar.messmenu add command -label "Reset all settings to default" -command { exec /bin/sh -c "sed 's%\.\./\.\./\.\.%$approot%' <'$messdir/mess.ini' >'$MESSHOME/mess.ini'"}
- .mbar.messmenu add command -label "Quit" -command { exit }
-
- set system ""
-
- #This function will be exected when the button is pushed
- proc startmess {} {
- global skip fileselect messdir loadenable MESSHOME system device
-
- set currdir [pwd]
- set args [.ent get]
- if { $skip==-1 } {
- set fskip "-autoframeskip"
- set pskip "auto"
- } else {
- set fskip "-frameskip $skip"
- set pskip $skip
- }
- set system_id [.lst curselection] ;#Get the no of the selected system
- if { $system_id=={} } { ;#If there is no system
- .txt delete 1.0 end
- .txt insert end "No system selected!"
- } else {
- set temp [.lst get $system_id] ;#Get the name of the system
- set system [lindex $temp 0]
- set desc [lindex $temp 1]
- set command "'$messdir/mess' $system $fskip $args"
- set dir "../../../Software/$system"
- if [catch {cd "$messdir/$dir"} errors] {
- if [catch {cd "$messdir/../../../Software"} errors] {
- cd "$messdir/../../.."
- }
- }
- set dir [pwd]
- .txt delete 1.0 end
- .txt insert end "System: $system\n"
- .txt insert end "Description: $desc\n"
- .txt insert end "Frame skip is: $pskip\n"
- .txt insert end "Command: $command\n"
- set devices ""
- while { $loadenable == 1 } {
- fileselect
- tkwait window .fileSelectWindow
- set diskfile $fileselect(selectedfile)
- set dir [pwd]
- if {$diskfile != "" } {
- if {$diskfile == ":UNLOAD:"} {
- set devices "$devices -$device \"\""
- } else {
- set devices "$devices -$device \"$dir/$diskfile\""
- }
- .txt insert end "$device: $diskfile\n"
- }
- # Reselect current system
- if { $system_id!={} } {
- .lst selection set $system_id
- }
- }
- # UGLY HACK
- # The following is part of a work around for a bug in mess 127 that affects
- # directory browsing.
- # exec /bin/sh -c "rm -f '$MESSHOME/Software'/* >/dev/null 2>&1 ; exit 0"
- # exec /bin/sh -c "ln * '$MESSHOME/Software' >/dev/null 2>&1 ; exit 0"
- # END UGLY HACK
- cd "$MESSHOME"
- set command "exec $command $devices"
- if [catch {exec /bin/sh -c $command} output] {
- .txt insert end "\nSDL Mess output:\n$output"
- }
- # UGLY HACK REMed OUT
- # The following was part of a work around for a bug in mess 127 that corrupts
- # file paths. This is no longer needed as it is corrected in the patched
- # version of sdlmess that is included.
- # The following line has been replaced with a new version below
- # exec /bin/sh -c "( test -f $system.ini && sed 's%\"$MESSHOME//%\"/%' <$system.ini | grep -v '^window ' | grep -v '^throttle ' | grep -v '^uimodekey ' | grep -v '^video ' >$system.ini.tmp 2>/dev/null ) ; exit 0"
- # END UGLY HACK REMed OUT
-
- ###############################################################################
- # These lines prevent certain settings from being saved into every systems ini
- # file.
- exec /bin/sh -c "( test -f $system.ini && grep -v '^window ' $system.ini | grep -v '^throttle ' | grep -v '^uimodekey ' | grep -v '^video ' >$system.ini.tmp 2>/dev/null ) ; exit 0"
- exec /bin/sh -c "( test -f $system.ini.tmp && rm -f $system.ini 2>/dev/null ) ; exit 0"
- exec /bin/sh -c "( test -f $system.ini.tmp && mv $system.ini.tmp $system.ini 2>/dev/null ) ; exit 0"
- ###############################################################################
-
- # UGLY HACK
- # The following is part of a work around for a bug in mess 127 that affects
- # directory browsing.
- # exec /bin/sh -c "rm -f '$MESSHOME/Software'/* >/dev/null 2>&1 ; exit 0"
- # END UGLY HACK
- }
- cd "$currdir"
- }
-
- proc listinfo {} {
- global appdir MESSHOME system messdir
-
- set currdir [pwd]
- set system_id [.lst curselection] ;#Get the no of the selected system
- if { $system_id=={} } { ;#If there is no system
- .txt delete 1.0 end
- .txt insert end "No system selected!"
- } else {
- set temp [.lst get $system_id] ;#Get the name of the system
- set system [lindex $temp 0]
- set desc [lindex $temp 1]
- .txt delete 1.0 end
- .txt insert end "System: $system\n"
- .txt insert end "Description: $desc\n"
- cd "$MESSHOME"
- set command "exec '$appdir/messinfo.sh' '$system' 1>&2"
- if [catch {exec /bin/sh -c $command} output] {
- .txt insert end "\n$output"
- }
- if { [file exists "$messdir/sysinfo/$system.htm"] } {
- exec open "$messdir/sysinfo/$system.htm"
- }
- }
- cd "$currdir"
- }
-
- proc doaudit {} {
- global messdir MESSHOME system
-
- set currdir [pwd]
- set system_id [.lst curselection] ;#Get the no of the selected system
- if { $system_id=={} } { ;#If there is no system
- .txt delete 1.0 end
- .txt insert end "No system selected!"
- } else {
- set temp [.lst get $system_id] ;#Get the name of the system
- set system [lindex $temp 0]
- set desc [lindex $temp 1]
- .txt delete 1.0 end
- .txt insert end "System: $system\n"
- .txt insert end "Description: $desc\n"
- cd "$MESSHOME"
- set command "exec '$messdir/mess' -verifyroms '$system' 1>&2"
- if [catch {exec /bin/sh -c $command} output] {
- .txt insert end "\n$output"
- }
- .txt insert end "\n"
- set command "exec '$messdir/mess' -listroms '$system' 1>&2"
- if [catch {exec /bin/sh -c $command} output] {
- .txt insert end "\n$output"
- }
- }
- cd "$currdir"
- }
-
- #Global Variables
- set skip -1
- #GUI building
- frame .frm_args
- label .lab -text "Custom arguments:"
- entry .ent -width 80
- #Frame skip
- frame .frm_settings
- label .fslab -text "Frame skip (-1 = auto)"
- scale .frmskip -orient v -digit 1 -from -1 -to 10 \
- -variable skip -tickinterval 1 -length 200
- #Load disk or cartridge
- checkbutton .load -text "Load/unload disk or cartridge" -variable loadenable
-
- #System list
- frame .frm_system
- mclistbox::mclistbox .lst -selectmode single -yscrollcommand ".y set" -height 20 -width 80
- .lst column add sys -label "System" -width 10
- .lst column add desc -label "Description" -width 70
- scrollbar .y -command ".lst yview" -orient v
-
-
- button .but -text "Start" -command "startmess"
- button .info -text "Info" -command "listinfo"
- button .audit -text "Verify ROM" -command "doaudit"
-
- #Text Area
- frame .textarea
- text .txt -yscrollcommand ".srl_y set" -xscrollcommand ".srl_x set" \
- -width 110 -height 10
- scrollbar .srl_y -command ".txt yview" -orient v
- scrollbar .srl_x -command ".txt xview" -orient h
-
- #Geometry Management
- grid .frm_args -in . -row 1 -column 1 -columnspan 4
- grid .lab -in .frm_args -row 1 -column 1
- grid .ent -in .frm_args -row 1 -column 2
- grid .frm_settings -in . -row 2 -column 1
- grid .fslab -in .frm_settings -row 1 -column 1
- grid .frmskip -in .frm_settings -row 2 -column 1
- grid .load -in .frm_settings -row 3 -column 1
- grid .frm_system -in . -row 2 -column 2 -columnspan 3
- grid .lst -in .frm_system -row 2 -column 1
- grid .y -in .frm_system -row 2 -column 2 -sticky ns
- grid .but -in . -row 4 -column 2 -sticky w
- grid .info -in . -row 4 -column 3 -sticky w
- grid .audit -in . -row 4 -column 4 -sticky w
- grid .txt -in .textarea -row 1 -column 1
- grid .srl_y -in .textarea -row 1 -column 2 -sticky ns
- grid .srl_x -in .textarea -row 2 -column 1 -sticky ew
- grid .textarea -in . -row 5 -column 1 -columnspan 4
- #Adding systems
- source sysinfo.tcl
-
- bind .lst <Up> {
- set system_id [.lst curselection] ;#Get the no of the selected system
- if {[llength $system_id] != 1} {
- # Listbox has more or less than one selected item
- return
- }
- .lst selection clear $system_id
- incr system_id -1
- if { $system_id < 0 } {
- set system_id 0
- }
- .lst see $system_id
- .lst selection set $system_id
- break
- }
-
- bind .lst <Down> {
- set system_id [.lst curselection] ;#Get the no of the selected system
- if {[llength $system_id] != 1} {
- # Listbox has more or less than one selected item
- return
- }
- .lst selection clear $system_id
- set previous $system_id
- incr system_id
- .lst see $system_id
- .lst selection set $system_id
- set system_id [.lst curselection] ;#Get the no of the selected system
- if {[llength $system_id] < 1} {
- set system_id $previous
- .lst see $system_id
- .lst selection set $system_id
- }
- break
- }
-
- bind .lst <Return> startmess
-
- bind .lst <KeyPress> {
- ListboxQuickSelect .lst %A
- }
-
- bind .lst <1> {+ focus %W}
-
- bind .frmskip <1> {+ focus %W}
-
- bind .frmskip <KeyPress> {
- set key "%A"
- if {[string equal $key ""]} {
- # %A substitute non unicode character by empty string
- return
- }
- if { [string is integer $key] } {
- set skip $key
- }
- if { [string equal $key -] } {
- set skip -1
- }
- }
-
- # ----------------------------------------------------------------------
- # ListboxQuickSelect --
- #
- # This command implements quick positioning inside a listbox
- # with key press. Each key pressed are buffered for the search.
- #
- # Typical usage is through binding:
- # bind $listbox <KeyPress> "ListboxQuickSelect %W %A"
- #
- # ----------------------------------------------------------------------
- proc ListboxQuickSelect {listbox key} {
- upvar 0 ::ListboxQuickSelect:$listbox data
-
- if {[string equal $key ""]} {
- # %A substitute non unicode character by empty string
- return
- }
- set sel [$listbox curselection]
- if {[llength $sel] > 1} {
- # Listbox has more than one selected item
- return
- }
-
- # Initialize index where search begin
- if {[llength $sel] == 1} {
- set startIndex [lindex $sel 0]
- } else {
- set startIndex 0
- }
-
- if {[info exists data(searchPrefix)]} {
- set searchPrefix $data(searchPrefix)
- } else {
- set searchPrefix ""
- }
-
- # if {[string equal -nocase $searchPrefix $key]} {
- # User presses twice the same key for the first char.
- # Search the next item which begin with that char (handled below).
- # } else {
- append searchPrefix $key
- # }
-
- # Skip current selected item if searchPrefix is one char
- # and selected item starts with this char.
- # if {[llength $sel] == 1 &&
- # [string length $searchPrefix] == 1 &&
- # [string match -nocase "$searchPrefix*" \
- # [ lindex [$listbox get $startIndex] 0 ]]} {
- # incr startIndex
- # }
- .txt delete 1.0 end
- .txt insert end "Searching for: $searchPrefix"
-
- # Now search for searchPrefix after current item,
- # and wrap if not found.
- foreach {start end} [list $startIndex end 0 $startIndex] {
- set index $start
- foreach item [$listbox get $start $end] {
- set curritem [lindex $item 0]
- if {[string match -nocase "$searchPrefix*" $curritem]} {
- set newSelectedIndex $index
- break
- }
- incr index
- }
-
- if {[info exists newSelectedIndex]} {
- # We have found a new item, select it and stop search
- $listbox selection clear 0 end
- $listbox selection set $newSelectedIndex
- $listbox see $newSelectedIndex
- break
- }
- }
-
- # Bufferize searchPrefix. Discard it in a small delay
- if {[info exists data(afterId)]} {
- after cancel $data(afterId)
- }
- set data(searchPrefix) $searchPrefix
- set data(afterId) [after 1000 "unset ::ListboxQuickSelect:$listbox"]
- }
-
- foreach event {<KeyPress> <<PasteSelection>>} {bind .txt $event break}
-
- bind .txt <Command-c> { event generate .txt <<Copy>> }
-
- bind .txt <Up> {
- .txt yview scroll -1 units
- }
-
- bind .txt <Down> {
- .txt yview scroll 1 units
- }
-
- bind .txt <Left> {
- .txt xview scroll -1 units
- }
-
- bind .txt <Right> {
- .txt xview scroll 1 units
- }
-
- #.lst selection clear 0 end
- #.lst selection set 0
- #.lst see 0
- #focus -force .lst
-